package cn.gx.kevin.dao.impl;
import cn.gx.kevin.dao.IRoleDao;
import cn.gx.kevin.dao.impl.BaseDao;
import cn.gx.kevin.domain.RoleMenu;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
import cn.gx.kevin.domain.Role;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
*Generate by Kevin's CodeBuilder
**/
@Repository(value="roleDao")
public class RoleDao extends BaseDao<Role, String> implements IRoleDao {
    @Override
    public List<RoleMenu> selectMenusByRole(Long roleId)  throws Exception{
        Map<String,Object> params = new HashMap<>();
        params.put("roleId",roleId);
        return this.selectParamE("selectMenusByRole",params);
    }

    @Override
    public void insertRoleMenus(List<RoleMenu> list)  throws Exception{
        if(list.size() > 0){
            SqlSession session = getSqlSession();
            Map<String, Object> params = new HashMap<>();
            String dbType = this.getDbType();
            params.put("list", list);
            params.put("dbType", dbType);
            session.insert(namespace + ".insertRoleMenus" , params);
        }
    }

    @Override
    public void deleteRoleMenu(Long roleId)  throws Exception{
        Map<String,Object> params = new HashMap<>();
        params.put("roleId",roleId);
        this.deleteRoleMenu(params);
    }


    @Override
    public void deleteRoleMenu(Map<String, Object> params) throws Exception {
        SqlSession session = this.getSqlSession();
        session.delete(namespace + ".deleteRoleMenu" ,params);
    }
}
